home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / Dev / Oberon / source / amiga / RealTime.mod < prev    next >
Text File  |  1995-06-29  |  10KB  |  312 lines

  1. (*************************************************************************
  2.  
  3.      $RCSfile: RealTime.mod $
  4.   Description: Interface to realtime.library
  5.  
  6.    Created by: fjc (Frank Copeland)
  7.     $Revision: 3.7 $
  8.       $Author: fjc $
  9.         $Date: 1995/06/04 23:13:14 $
  10.  
  11.   Includes Release 40.15
  12.  
  13.   (C) Copyright 1993 Commodore-Amiga, Inc.
  14.       All Rights Reserved
  15.  
  16.   Oberon-A Interface Copyright © 1994-1995, Frank Copeland.
  17.   This file is part of the Oberon-A Interface.
  18.   See Oberon-A.doc for conditions of use and distribution.
  19.  
  20.   Log entries are at the end of the file.
  21.  
  22. *************************************************************************)
  23.  
  24. <* STANDARD- *>
  25.  
  26. MODULE [2] RealTime;
  27.  
  28. IMPORT SYS := SYSTEM, Kernel, e := Exec, u := Utility, s := Sets;
  29.  
  30. (*
  31. **      $VER: realtime.h 40.3 (5.4.93)
  32. **
  33. **      realtime.library timing and syncing system
  34. *)
  35.  
  36. (*****************************************************************************)
  37.  
  38. CONST
  39.  
  40. (* realtime.library's idea of time is based on a clock which emits a pulse
  41.  * 1200 times a second (1.2kHz). All time values maintained by realtime.library
  42.  * are based on this number. For example, the field RealTimeBase->rtb_Time
  43.  * expresses an amount of time equivalent to (RealTimeBase->rtb_Time/TICK_FREQ)
  44.  * seconds.
  45.  *)
  46.   tickFreq * = 1200;
  47.  
  48.  
  49. (*****************************************************************************)
  50.  
  51. TYPE
  52.  
  53. (* Each Conductor represents a group of applications which wish to remain
  54.  * synchronized together.
  55.  *
  56.  * This structure must only be allocated by realtime.library and is
  57.  * READ-ONLY!
  58.  *)
  59.   ConductorPtr * = POINTER TO Conductor;
  60.   Conductor * = RECORD (e.NodeBase)
  61.     node -            : e.Node;
  62.     reserved0 -       : e.UWORD;
  63.     players -         : e.MinList; (* this conductor's players      *)
  64.     clockTime -       : e.ULONG;   (* current time of this sequence *)
  65.     startTime -       : e.ULONG;   (* start time of this sequence   *)
  66.     externalTime -    : e.ULONG;   (* time from external unit       *)
  67.     maxExternalTime - : e.ULONG;   (* upper limit on sync'd time    *)
  68.     metronome -       : e.ULONG;   (* MetricTime highest pri node   *)
  69.     reserved1 -       : e.UWORD;
  70.     flags -           : s.SET16;   (* conductor flags               *)
  71.     state -           : SHORTINT;  (* playing or stopped            *)
  72.   END;
  73.  
  74. CONST
  75.  
  76. (* Flag bits for Conductor.cdt_Flags *)
  77.   external * = 0;       (* clock is externally driven *)
  78.   gotTick *  = 1;       (* received 1st external tick *)
  79.   metroSet * = 2;       (* cdt_Metronome filled in    *)
  80.   private *  = 3;       (* conductor is private       *)
  81.  
  82. (* constants for Conductor.cdt_State and SetConductorState() *)
  83.   stopped * = 0;          (* clock is stopped              *)
  84.   paused *  = 1;          (* clock is paused               *)
  85.   locate *  = 2;          (* go to 'running' when ready    *)
  86.   running * = 3;          (* run clock NOW                 *)
  87.  
  88. (* These do not actually exist as Conductor states, but are used as additional
  89.  * arguments to SetConductorState()
  90.  *)
  91.   metric *    = -1;       (* ask high node to locate       *)
  92.   shuttle *   = -2;       (* time changing but not running *)
  93.   locateSet * = -3;       (* maestro done locating         *)
  94.  
  95.  
  96. (*****************************************************************************)
  97.  
  98. TYPE
  99.  
  100. (* The Player is the connection between a Conductor and an application.
  101.  *
  102.  * This structure must only be allocated by realtime.library and is
  103.  * READ-ONLY!
  104.  *)
  105.   PlayerPtr * = POINTER TO Player;
  106.   Player * = RECORD (e.NodeBase)
  107.     node -       : e.Node;
  108.     reserved0 -  : SHORTINT;
  109.     reserved1 -  : SHORTINT;
  110.     hook -       : u.HookPtr;     (* player's hook function       *)
  111.     source -     : ConductorPtr;  (* pointer to parent context    *)
  112.     task -       : e.TaskPtr;     (* task to signal for alarm     *)
  113.     metricTime - : LONGINT;       (* current time in app's metric *)
  114.     alarmTime -  : LONGINT;       (* time to wake up              *)
  115.     userData -   : e.APTR;        (* for application use          *)
  116.     playerID -   : e.UWORD;       (* for application use          *)
  117.     flags -      : s.SET16;       (* general Player flags         *)
  118.   END;
  119.  
  120. CONST
  121.  
  122. (* Flag bits for Player.pl_Flags *)
  123.   ready     * = 0;          (* player is ready to go!        *)
  124.   alarmSet  * = 1;          (* alarm is set                  *)
  125.   quiet     * = 2;          (* a dummy player, used for sync *)
  126.   conducted * = 3;          (* give me metered time          *)
  127.   extSync   * = 4;          (* granted external sync         *)
  128.  
  129.  
  130. (*****************************************************************************)
  131.  
  132. CONST
  133.  
  134. (* Tags for CreatePlayer(), SetPlayerAttrs(), and GetPlayerAttrs() *)
  135.   playerBase *         = u.user + 64;
  136.   playerHook *         = playerBase+1;   (* set address of hook function *)
  137.   playerName *         = playerBase+2;   (* name of player               *)
  138.   playerPriority *     = playerBase+3;   (* priority of player           *)
  139.   playerConductor *    = playerBase+4;   (* set conductor for player     *)
  140.   playerReady *        = playerBase+5;   (* the "ready" flag             *)
  141.   playerAlarmTime *    = playerBase+12;  (* alarm time (sets PLAYERF_ALARMSET) *)
  142.   playerAlarm *        = playerBase+13;  (* sets/clears PLAYERF_ALARMSET flag  *)
  143.   playerAlarmSigTask * = playerBase+6;   (* task to signal for alarm/notify    *)
  144.   playerAlarmSigBit *  = playerBase+8;   (* signal bit for alarm (or -1) *)
  145.   playerConducted *    = playerBase+7;   (* sets/clears PLAYERF_CONDUCTED flag   *)
  146.   playerQuiet *        = playerBase+9;   (* don't process time thru this *)
  147.   playerUserData *     = playerBase+10;
  148.   playerID *           = playerBase+11;
  149.   playerExtSync *      = playerBase+14;  (* attempt/release to ext sync  *)
  150.   playerErrorCode *    = playerBase+15;  (* error return value           *)
  151.  
  152.  
  153. (*****************************************************************************)
  154.  
  155. CONST
  156.  
  157. (* Method types for messages sent via a Player's hook *)
  158.   pmTick * = 0;
  159.   pmState * = 1;
  160.   pmPosition * = 2;
  161.   pmShuttle * = 3;
  162.  
  163. TYPE
  164.  
  165.   MsgPtr * = POINTER TO Msg;
  166.   Msg * = RECORD END;
  167.  
  168. (* used for PM_TICK, PM_POSITION and PM_SHUTTLE methods *)
  169.   PMTimePtr * = POINTER TO PMTime;
  170.   PMTime * = RECORD (Msg) (* PM_TICK, PM_POSITION, or PM_SHUTTLE *)
  171.     method * : e.ULONG;
  172.     time *   : e.ULONG;
  173.   END;
  174.  
  175. (* used for the PM_STATE method *)
  176.   PMStatePtr * = POINTER TO PMState;
  177.   PMState * = RECORD (Msg) (* PM_STATE *)
  178.     method *   : e.ULONG;
  179.     oldState * : e.ULONG;
  180.   END;
  181.  
  182.  
  183. (*****************************************************************************)
  184.  
  185. CONST
  186.  
  187. (* Possible lock types for LockRealTime() *)
  188.   conductors * = 0;     (* conductor list *)
  189.  
  190.  
  191. (*****************************************************************************)
  192.  
  193. CONST
  194.  
  195. (* realtime.library error codes *)
  196.   noMemory *    = 801;  (* memory allocation failed      *)
  197.   noConductor * = 802;  (* player needs a conductor      *)
  198.   noTimer *     = 803;  (* timer (CIA) allocation failed *)
  199.   playing *     = 804;  (* can't shuttle while playing   *)
  200.  
  201.  
  202. (*****************************************************************************)
  203.  
  204. TYPE
  205.  
  206. (* OpenLibrary("realtime.library",0) returns a pointer to this structure.
  207.  * All fields are READ-ONLY.
  208.  *)
  209.   RealTimeBasePtr * = POINTER TO RealTimeBase;
  210.   RealTimeBase * = RECORD (e.LibraryBase)
  211.     libNode -   : e.Library;
  212.     reserved0 - : ARRAY 2 OF e.UBYTE;
  213.  
  214.     time -      : e.ULONG;   (* current time                         *)
  215.     timeFrac -  : e.ULONG;   (* fixed-point fraction part of time    *)
  216.     reserved1 - : e.UWORD;
  217.     tickErr -   : INTEGER;   (* nanosecond error from ideal Tick     *)
  218.   END;                       (* length to real tick length           *)
  219.  
  220. CONST
  221.  
  222. (* Actual tick length is: 1/TICK_FREQ + rtb_TickErr/1e9 *)
  223.  
  224.   tickErrMin * = -705;
  225.   tickErrMax * = 705;
  226.  
  227.  
  228. (*****************************************************************************)
  229.  
  230. (*-- Library Base variable --------------------------------------------*)
  231.  
  232. VAR
  233.  
  234.   base* : RealTimeBasePtr;
  235.  
  236.  
  237. (*-- Library Functions ------------------------------------------------*)
  238.  
  239. TYPE
  240.   RealTimeLock * = POINTER TO RECORD END;
  241.  
  242. (*
  243. **      $VER: realtime_protos.h 40.1 (16.3.93)
  244. *)
  245.  
  246. (*--- functions in V37 or higher (Release 2.04) ---*)
  247.  
  248. (* Locks *)
  249.  
  250. PROCEDURE LockRealTime* [base,-30]
  251.   ( lockType [0] : e.ULONG )
  252.   : RealTimeLock;
  253.  
  254. PROCEDURE UnlockRealTime* [base,-36]
  255.   ( lock [8] : RealTimeLock );
  256.  
  257. (* Conductor *)
  258.  
  259. PROCEDURE CreatePlayerA* [base,-42]
  260.   ( tagList [8] : ARRAY OF u.TagItem )
  261.   : PlayerPtr;
  262.  
  263. PROCEDURE CreatePlayer* [base,-42]
  264.   ( tagList [8]..: u.Tag )
  265.   : PlayerPtr;
  266.  
  267. PROCEDURE DeletePlayer* [base,-48]
  268.   ( player [8] : PlayerPtr );
  269.  
  270. PROCEDURE SetPlayerAttrsA* [base,-54]
  271.   ( player  [8] : PlayerPtr;
  272.     tagList [9] : ARRAY OF u.TagItem )
  273.   : BOOLEAN;
  274.  
  275. PROCEDURE SetPlayerAttrs* [base,-54]
  276.   ( player  [8]  : PlayerPtr;
  277.     tagList [9]..: u.Tag )
  278.   : BOOLEAN;
  279.  
  280. PROCEDURE SetConductorState* [base,-60]
  281.   ( player [8] : PlayerPtr;
  282.     state [0]  : e.ULONG;
  283.     time [1]   : LONGINT )
  284.   : LONGINT;
  285.  
  286. PROCEDURE ExternalSync* [base,-66]
  287.   ( player  [8] : PlayerPtr;
  288.     minTime [0] : LONGINT;
  289.     maxTime [1] : LONGINT )
  290.   : BOOLEAN;
  291.  
  292. PROCEDURE NextConductor* [base,-72]
  293.   ( previousConductor [8] : ConductorPtr )
  294.   : ConductorPtr;
  295.  
  296. PROCEDURE FindConductor* [base,-78]
  297.   ( name [8] : ARRAY OF CHAR )
  298.   : ConductorPtr;
  299.  
  300. PROCEDURE GetPlayerAttrsA* [base,-84]
  301.   ( player  [8] : PlayerPtr;
  302.     tagList [9] : ARRAY OF u.TagItem )
  303.   : e.ULONG;
  304.  
  305. PROCEDURE GetPlayerAttrs* [base,-84]
  306.   ( player  [8]  : PlayerPtr;
  307.     tagList [9]..: u.Tag )
  308.   : e.ULONG;
  309.  
  310. BEGIN base := NIL
  311. END RealTime.
  312.